#include "mainwindow.h"

#include <QApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

////#include "stdafx.h"
//#include <windows.h>
//#include <iostream>
//#include <string>
//#include <setupapi.h>
//#include <initguid.h>
//using namespace std;

//#pragma comment(lib,"setupapi.lib")

//DEFINE_GUID (UsbClassGuid, 0xa5dcbf10L, 0x6530, 0x11d2, 0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed);

////获取USB设备VID和PID
//string GetUsbInfo()
//{

//     HDEVINFO hDevInfo;

//     SP_DEVICE_INTERFACE_DATA spDevData;

//     PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;

//     BOOL bRes = TRUE;

//     int nCount = 0;
//     string csResult;
//     hDevInfo = ::SetupDiGetClassDevs((LPGUID) &UsbClassGuid,NULL,NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);

//     if (hDevInfo != INVALID_HANDLE_VALUE)
//     {

//         pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT,1024);

//         pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

//         while (bRes)
//         {
//             spDevData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//             bRes = ::SetupDiEnumDeviceInterfaces(hDevInfo,NULL,(LPGUID)&UsbClassGuid,nCount,&spDevData);

//             if (bRes)
//             {
//                 bRes = ::SetupDiGetInterfaceDeviceDetail(hDevInfo,&spDevData,pDetail,1024,NULL,NULL);

//                 if (bRes)
//                 {
//                     wstring wszStr = pDetail->DevicePath;
//                     string szStr(wszStr.begin(), wszStr.end());// = pDetail->DevicePath;
//                     csResult += szStr +"\n";
//                     nCount ++;
//                 }
//             }

//         }
//         ::GlobalFree(pDetail);
//         ::SetupDiDestroyDeviceInfoList(hDevInfo);
//     }

//     return csResult;
//}

//int main34(int argc, char *argv[])
//{

//      string csStr = GetUsbInfo();

//      qDebug() << QString::fromStdString( csStr);

//      cout<< csStr<<endl;

//      return 0;

//}

#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void PrintSize(const char* const message, const DWORD sizeBytes)
{
    cout << message << ": " << sizeBytes << " bytes ("
         << (sizeBytes/sizeof(wchar_t)) << " wchar_t's)\n";
}

int mai99n(int argc, char *argv[])
{
    const HKEY key = HKEY_LOCAL_MACHINE;
    const wchar_t* const subKey = L"SYSTEM\\ControlSet001\\Enum\\USB\\VID_24AE&PID_2013&MI_01";
    const wchar_t* const valueName = L"CommonFilesDir";
//HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\USB
    DWORD dataSize = 256;
    const DWORD flags = RRF_RT_ANY;
    DWORD dataType;

    vector<wchar_t> buffer(dataSize / sizeof(wchar_t));
    LONG result= ::RegGetValue(
            key,
            subKey,
            valueName,
            flags,
            &dataType,
            &buffer[0],
            &dataSize);
    if (result != ERROR_SUCCESS)
    {
        cout << "Error: " << result << '\n';
        return 1;
    }
    PrintSize("2nd call size", dataSize);

    const wstring text(buffer.data());
    cout << "Read string:\n";
    wcout << text << '\n';
    wcout << wstring(dataSize/sizeof(wchar_t), L'*')  << "  <-- 2nd call size\n";
        return 0;
}

